﻿using System;
using System.Drawing;
using System.Web.UI;
using System.Web.UI.WebControls;
using Model;

public partial class CustomControls_FeaturedCategory : UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
        try
        {
            Categories featured = Entities.GetFeaturedCategory();

            var img = new Bitmap(Utils.GetApplicationSetting(Constants.IMAGES_CATEGORIES_PHYSICAL_PATH) + featured.ImagePath);
            if (img.Width > img.Height) imgFeatured.Width = new Unit(200);
            else imgFeatured.Height = new Unit(200);
            imgFeatured.AlternateText = featured.Title;

            imgFeatured.ImageUrl = Utils.GetApplicationSetting(Constants.IMAGES_CATEGORIES_URL_PREFIX).Replace("~", "") + featured.ImagePath;
            linkTitle.Text = featured.Title;
            linkTitle.NavigateUrl = "/" + Utils.BuildURL(PageType.Categorii, featured.CategoryID, Server.UrlEncode(featured.Title));
            linkMore.NavigateUrl = "/" + Utils.BuildURL(PageType.Categorii, featured.CategoryID, Server.UrlEncode(featured.Title));
            linkImage.NavigateUrl = "/" + Utils.BuildURL(PageType.Categorii, featured.CategoryID, Server.UrlEncode(featured.Title));
            lblContent.Text = featured.Description;
        }
        catch
        {
            pnlFeaturedCategory.Visible = false;
        }
    }
}